﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fly : MonoBehaviour {

    public Vector3 startPosition;
    public Vector3 endPosition;
    public float speed = 0.2f;

	// Use this for initialization
	void Start () {
        StartCoroutine(Move());
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    IEnumerator Move()
    {
        float _distance = 1;
        while (true)
        {
            if (_distance >= 0.1f)
            {
                _distance = Vector3.Distance(transform.position, endPosition);
                transform.position = Vector3.Lerp(transform.position, endPosition, Time.deltaTime * speed);
                yield return null;
            }
            else
            {
                transform.position = startPosition;
                _distance = Vector3.Distance(transform.position, endPosition);
                yield return null;
            }
        }
    }
}
